import 'package:flutter_demo/pages/home.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

/// @author longzipeng
/// @创建时间：2022/2/16
/// 配置项目中的路由
class Routes {
  /// 定义路由名称
  static String home = "/";

  static late FluroRouter router;

  /// 定义路由处理函数
  static final Handler _homeHandler = Handler(handlerFunc:
      (BuildContext? context, Map<String, List<String>> parameters) {
    return const HomePage();
  });

  /// 关联路由名称和处理函数
  static void defineRoutes() {
    _defineRoutesWithDefaultAnimation(home, _homeHandler);
  }

  /// 设置路由并设置默认路由动画
  static void _defineRoutesWithDefaultAnimation(String url, Handler handler) {
    router.define(url,
        handler: handler, transitionType: TransitionType.inFromRight);
  }

  /// 将url和对应路由的页面进行绑定
  static void configureRoutes(FluroRouter routerParam) {
    router = routerParam; // 初始化路由实例
    defineRoutes(); // 调用路由配置方法
  }
}
